

$(document).ready(function(){
	
	var phone=$("#phoneNumber").val();
	findIntroducerlist(phone);
	
});

//搜索
function searchList(){
	var phone=$("#phoneNumber").val();
	findIntroducerlist(phone);
}


/**
 * 获取介绍人列表
 */

function findIntroducerlist(phone){
	
		$.ajax({
			url: urlcore + "/api/introducer/findIntroducerlist?phone="+phone,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			data: {},
			processData: false,
			success:function(data){
				if(data.success == true){
					$("#thislist").html("");
					var da=data.data;var html="";
					for(var i=0,y=da.length;i<y;i++){
						var avatarUrl=da[i].avatarUrl;
			      html += "  <tr >\n" +
			            " <td>" + (i + 1) + "</td>\n" +
			            " <td>" + da[i].nickName + "</td>\n" +
			            " <td>" + da[i].realName + "</td>\n" +
			            " <td>" + da[i].phone + "</td>\n" +
			            " <td>" + da[i].age + "</td>\n" +
			            " <td>" + da[i].sex + "</td>\n" +
			            " <td class=\"footable-visible\"><img width=\"40px\" height=\"40px\" src=\"" + avatarUrl + "\"></td>\n" +
			            " <td>" + da[i].profitability + "</td>\n" +
			            " <td>\n" +
			            " <a class=\"btn btn-primary btn-xs\" href=\"javascript:;\" onclick=\"doDelete(" + da[i].id + ")\"> 删除</a>\n" +
			            " </td>\n" +
			            " </tr>";
						
					}
					$("#thislist").append(html);
					
				}else{
					alert(data.msg);
				}
			},
			error:function() {
				/*alert("error");*/
			}
		});
	
	
}




function doDelete(id){
	
	   $.ajax({
        type: "GET",
        url: urlcore + "/api/introducer/delOne?id=" + id,
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        data: {},
        success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
            if (data.success == true) {
            	alert(data.msg);
                location.reload();
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            alert("删除失败");
        }
    });
	
	
}
